type TBase64ToFile = (base64: string, filename: string) => File;

//base64 转 File
const base64ToFile: TBase64ToFile = (base64, filename) => {
  const arr: any = base64.split(",");
  const mime = arr[0].match(/:(.*?);/)[1];
  const bstr = atob(arr[1]);
  let n = bstr.length;
  const u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  const file = new File([u8arr], filename, { type: mime });
  return file;
};

export default base64ToFile;
